package CaseTraining;

public class CaseDemo04 {
    public static void main(String[] args) {
        System.out.println(encrypt(1983));
    }
    public static String encrypt(int number){
        //得到一个数字后对数字进行拆分
        //调用split方法
        int[] numbers = split(number);
        //遍历每一个元素进行加密步骤 先+5 后 除以10求余
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = (numbers[i] + 5) % 10;
        }
        //对新的数组进行反转，调用反转方法
        reverse(numbers);
        //将数组元素合并
        String data ="";
        for (int i = 0; i < numbers.length; i++) {
            data += numbers[i];
        }
        return data;
    }

    //反转方法
    public static int[] reverse(int[] numbers){
        for (int i = 0 , j = numbers.length - 1; i < j; i++, j--) {
            int temp = numbers[i];
            numbers[i] = numbers[j];
            numbers[j] = temp;
        }
        return numbers;
    }

    //对数字拆分的方法
    public static int[] split(int number){
        int[] numbers = new int[4];
        numbers[0] = number / 1000;
        numbers[1] = (number / 100) % 10;
        numbers[2] = (number / 10) % 10;
        numbers[3] = number % 10;
        return numbers;
    }
}
